#!/usr/bin/env python

"""
        __author__      = "Vishal Patil"
        __copyright__   = "Copyright (C) 2006 Vishal Patil"
"""

from pgap import NaturalSelector
from pgap import Population

#
#	This class is used to select the best chromosones as per the fitness
#	value	
#

class BestChromosonesSelector(NaturalSelector.NaturalSelector):
	
	#
	#	Sort the chromosones as per fitness and select the best 
	#	'count' of them
	#
	def select(self,population,count):
		bestChromosones = []
		chromosones = population.getChromosones()

		if len(chromosones) == 0:
			raise "No chromosones found"
		
		chromosones.sort()
		bestChromosones = chromosones[0:count]
		return bestChromosones 
			
		
